<?php

namespace Wechat\Controller;

class DoctorController extends CommonController  {

    /**
     * 医生列表页
     */
    public function index() {
        $categoryId = isNullOrEmpty($_REQUEST["categoryId"]) ? "0" : $_REQUEST["categoryId"];
        $this->assign("categoryId", $categoryId);
        $this->display("index");
    }

    /**
     * 医生列表筛选
     */
    public function doctorList() {

        $cityId = I("post.cityId");
        $categoryId = I("post.categoryId");
        $doctorName = I("post.doctorName");

        if(!isNullOrEmpty($doctorName)) {
            $map["d.doctor_name"] = array("like", '%' . $doctorName . '%');
        }

        if(!isNullOrEmpty($cityId)) {
            $map["d.city_id"] = $cityId;
        }

        if(!isNullOrEmpty($categoryId)) {
            $map["dc.category_id"] = $categoryId;
        }

        $list = D("Doctor")->alias("d")
            ->join("left join __DOCTOR_CATEGORY__ dc on dc.doctor_id = d.doctor_id")
            ->where($map)
            ->field("d.doctor_id, d.image_url, d.doctor_name, 
                d.hospital_name, d.brief")
            ->group("d.doctor_id")
            ->select();

        $index = 1;
        foreach ($list as &$item) {
            $item["index"] = $index++;
        }

        echo json_encode($list);

    }

    /*
     * 医生详情
     */
    public function detail() {

        $id = $_REQUEST["id"];
        $info = D("Doctor")->queryById($id);

        $this->assign("customer", $this->customer);
        $this->assign("info", $info);
        $this->display("detail");
    }

}